package vip.zhenzicheng;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
import org.springframework.cloud.zookeeper.discovery.ZookeeperServiceWatch;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @author zhenzicheng
 * @DESCRIPTION:
 * @DATE: 2022/04/25 1:45 PM
 */
@Component
@Slf4j
public class HeartbeatEventListener implements ApplicationListener<HeartbeatEvent> {
  @Override
  public void onApplicationEvent(HeartbeatEvent heartbeatEvent) {
    Object value = heartbeatEvent.getValue();
    ZookeeperServiceWatch source = (ZookeeperServiceWatch) heartbeatEvent.getSource();

    log.info("event:source: {},event:value{}", source.getCache().getCurrentChildren("/services"), value.toString());
  }
}
